package com.matt.repository.estimate;

import com.matt.domain.estimate.LikedRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.ArrayList;

public interface LikedRecordRepository extends JpaRepository<LikedRecord, String> {

    //统计点赞总数
    @Query(value = "SELECT COUNT(*)  FROM `like_record` WHERE bizId = ? AND bizType = ?", nativeQuery = true)
    Integer countByBizIdAndBizType(String bizId, String bizType);

    // 查询用户师傅点赞
    @Query(value = "SELECT * FROM like_record WHERE userId = ? AND bizType = ?", nativeQuery = true)
    ArrayList<LikedRecord> findAllByUserIdAndBizType(String userId, String bizType);

    // 新增点赞
    @Query(value = "INSERT INTO like_record(userId, bizId, bizType, createDate VALUES (?, ?, ?, ?)", nativeQuery = true)
    LikedRecord addLikedRecord(String userId, String bizId, String bizType, String createDate);

    // 取消点赞
    @Modifying
    @Query(value = "DELETE FROM like_record WHERE userId = ?1 AND bizId = ?2", nativeQuery = true)
    void deleteLikedRecordByUserIdAndBizId(String userId, String biz_id);
}
